Release 10.1A: OpenEdge Development:
Progress Dynamics Administration


Writing a load program

The load program is slightly more complicated than the dump program because it must verify the referential integrity of the data. The following shows a sample load program using both default and user-supplied code to import the contents of the gsm_menu_structure_item table:

gsmitin.p sample with user-supplied code for referential integrity
/* gsmitin.p */ 
&SCOPED-DEFINE InputTable gsm_menu_structure_item 
&SCOPED-DEFINE ObjField menu_structure_item_obj 
{db/icf/dfd/sitedataprocin.i 
  &InputFile = "'gsmitout.d'" 
  } 
{db/icf/dfd/siteapplyrechdr.i} 
  IF NOT CAN-FIND(FIRST gsm_menu_structure 
                    WHERE gsm_menu_structure.menu_structure_obj = 
tt_{&InputTable}.menu_structure_obj) THEN 
    RETURN. 
  IF tt_{&InputTable}.menu_item_obj <> 0.00 AND 
     NOT CAN-FIND(FIRST gsm_menu_item 
                    WHERE gsm_menu_item.menu_item_obj = 
tt_{&InputTable}.menu_item_obj) THEN 
    RETURN. 
  IF tt_{&InputTable}.child_menu_structure_obj <> 0.00 AND 
     NOT CAN-FIND(FIRST gsm_menu_structure 
                    WHERE gsm_menu_structure.menu_structure_obj = 
tt_{&InputTable}.child_menu_structure_obj) THEN 
    RETURN. 
  /* Duplicate record */ 
  IF CAN-FIND(FIRST gsm_menu_structure_item  
                WHERE gsm_menu_structure_item.menu_structure_obj = 
tt_{&InputTable}.menu_structure_obj 
                  AND gsm_menu_structure_item.menu_item_sequence = 
tt_{&InputTable}.menu_item_sequence) THEN 
    RETURN. 
{db/icf/dfd/siteapplyrecftr.i} 

The InputTable compiler directive contains the name of the table for which data is to be imported. The ObjField compiler directive specifies the field that is the object ID field for the table. The InputFile include file directive specifies the name of the file to be used as the source of the data to be imported.

This load program takes the ttDumpFileLocation table as an input parameter (sitedatahdrin.i from within sitedataprocin.i), and the above default code reads that data into a temp-table that is constructed LIKE the table being imported (sitedataprocin.i). The temp-table is named tt_Table, where Table is the name of the table that is being imported.

Once the code in sitedataprocin.i has imported the code into the temp-table, a buffer to the temp-table is passed to an internal procedure called applyRecord. This is the only piece of code that must be customized. The header for this internal procedure is contained in siteapplyrechdr.i. By default, this code checks to see if a record exists with the object ID of the current record. If it does, the code assumes that the data has been supplied by the ADOs and that it should not be changed.

The footer for the applyRecord procedure is contained in siteapplyrecftr.i and includes the transaction that commits the data in the temp-table to the database.

You (or your end-user) supply all of the code specified between the siteapplyrechdr.i and siteapplyrecftr.i include file references. This code is responsible for verifying the referential integrity of the data being imported. If any of the integrity checks fail, control returns to the caller. This results in the main block importing the next record from the .d file and verifying that it is correct.

You can completely customize the code for the load program, as in the following example:

gsmitin.p sample with completely customized code
/* sitedatahdrin contains the parameter definitions for the import program. */ 
{db/icf/dfd/sitedatahdrin.i} 
DEFINE VARIABLE iLineNo    AS INTEGER    NO-UNDO. 
DEFINE TEMP-TABLE tt_{&InputTable} LIKE {&InputTable}. 
/* Find the import file name */ 
FIND ttDumpFileLocation  
  WHERE ttDumpFileLocation.cDumpFile = {&InputFile} 
  NO-ERROR. 
/* If its not available, ignore it and let the caller call the next import 
program */ 
IF NOT AVAILABLE(ttDumpFileLocation) OR 
   ttDumpFileLocation.cDumpFilePath = ? THEN 
  RETURN. 
/* Look for the dump file on disk. */ 
IF SEARCH(ttDumpFileLocation.cDumpFilePath) = ? THEN 
DO: 
  PUBLISH "DCU_WriteLog":U ("WARNING: Import file not found: " +  
                            ttDumpFileLocation.cDumpFilePath). 
  RETURN. 
END. 
ELSE 
DO: 
  PUBLISH "DCU_WriteLog":U ("Reading data from: " +  
                            ttDumpFileLocation.cDumpFilePath). 
END. 
/* Open the input stream for the dump file */ 
INPUT FROM VALUE(ttDumpFileLocation.cDumpFilePath). 
/* Loop until we have read the whole dump file. */ 
REPEAT: 
  /* Import the data from the .d file */ 
  CREATE tt_{&InputTable}. 
  IMPORT tt_{&InputTable}. 
  iLineNo = iLineNo + 1. 
  /* Do whatever referential integrity checks here */ 
  DELETE tt_{&InputTable}. 
END. 
INPUT CLOSE. 
PUBLISH "DCU_WriteLog":U ("Finished reading data from: " +  
                          ttDumpFileLocation.cDumpFilePath). 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095